import sys
import numpy as np

sys.path.append("D:\\pyitem\\soccer\\data_processing")
from data_processing.yaml_weight import DataInformation


# 对数据进行权重评分
class CMScore:
    # 初始化数据
    def __init__(self, player_data, position=DataInformation().weight_data("CM")):
        self.position = position
        self.player_data = player_data
        self.Integral = 0

    def score(self):
        """
        对数据里除了名字位置的每个数值进行计算
        :return:
        返回处理好的字典数据类型
        """
        # 循环获取字典中的每个键名
        for i in self.player_data.keys():
            # 判断获取的值是否为int类型，如果不是就pass
            if isinstance(self.player_data[i], int):
                # 对获取到的数值进行求值替换
                score = self.player_data[i] * self.position[i]
                self.player_data[i] = float('%.1f' % score)
            else:
                pass
        # 判断是否胜利了，胜利了+3分，输了-2分
        if self.player_data['Wins'] == 1:
            self.Integral += 3
        elif self.player_data['Loses'] == 1:
            self.Integral -= 2
        # 添加运算好的键值对
        self.player_data['Integral'] = self.Integral
        return self.player_data


if __name__ == "__main__":
    D = {'Players Name': 'Cheese_起飔', 'Positions': 'CM', 'games played': 1, 'Passes': 7, 'Assists': 0, 'Shots': 0,
         'Goals': 0, 'TKLs': 2, 'INTs': 2, 'Catches': 0, 'Saves': 0, 'Wins': 0, 'Loses': 1}
    print(CMScore(D).score())
